<template>
  <div class="ContentList">
    <div class="SelectMes">
      <div class="left">
        <div class="leftinput">
          <span>学校名称</span
          ><el-input v-model="schoolname" placeholder="请输入学校名称" />
        </div>
        <div class="leftinput">
          <span>学生姓名</span>
          <el-input v-model="studentname" placeholder="请输入学生姓名" />
        </div>
        <div class="leftselect">
          <span>全部课程</span>
          <el-select v-model="value" class="m-2" placeholder="Select">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>

        <div class="leftselect other">
          <span>性别</span>
          <el-select v-model="value" class="m-2" placeholder="Select">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div class="leftselect other">
          <span>班级</span>
          <el-select v-model="value" class="m-2" placeholder="Select">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
      </div>
      <div class="right">
        <el-button class="bluebtn" @click="searchlink(studentname)">
          <img src="../../assets/list/serch_white.svg" alt="" />
          查询</el-button
        >
        <el-button class="whitebtn" @click="resetlist">
          <img src="../../assets/list/refresh.svg" alt="" />
          重置</el-button
        >
      </div>
    </div>

    <div class="UserList">
      <div class="otherbutton">
        <el-button class="newbutton">
          <img src="../../assets/list/plus.svg" alt="" />
          新建</el-button
        >

        <el-button class="downbutton">
          <img src="../../assets/list/down.svg" alt="" />导出</el-button
        >
      </div>
      <div class="detailList">
        <el-table
          :data="
            userData.listdata.slice(
              (currentPage - 1) * PageSize,
              currentPage * PageSize
            )
          "
          style="width: 100%"
          :header-cell-style="{
            background: '#F5F7FB',
            color: 'rgba(53,62,73,1)',
          }"
        >
          <el-table-column prop="id" label="编号" width="80" />
          <el-table-column prop="school" label="学校" width="220" />
          <el-table-column prop="course" label="课程" width="200" />
          <el-table-column prop="name" label="姓名" width="100" />
          <el-table-column prop="grade" label="年级" width="100" />
          <el-table-column prop="class" label="班级" width="100" />
          <el-table-column prop="phonenumber" label="联系电话" />
          <el-table-column prop="time" label="时间" width="200" />
          <el-table-column fixed="right" label="操作" width="120">
            <template #default="scope">
              <el-button
                link
                type="danger"
                size="small"
                @click="handleDelete(scope.$index, scope.row)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            v-model:currentPage="currentPage"
            v-model:page-size="PageSize"
            :current-page="currentPage"
            layout="total, prev, pager, next"
            :total="userData.listdata.length"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { reactive, ref } from "vue";
import { Vue } from "vue-class-component";
//引入api
import link from "../../api/link";
import apiUrl from "../../api/apiUrl";
//引入store
import { useStore } from "vuex";
export default class Container extends Vue {
  input = ref("");
  value = ref("");
  schoolname = ref("");
  studentname = ref("");
  //定义动态数组
  userData = reactive({
    listdata: [],
  });

  options = [
    {
      value: "Option1",
      label: "Option1",
    },
    {
      value: "Option2",
      label: "Option2",
    },
    {
      value: "Option3",
      label: "Option3",
    },
    {
      value: "Option4",
      label: "Option4",
    },
    {
      value: "Option5",
      label: "Option5",
    },
  ];
  //查询
  searchlink = (studentname) => {
    // if (this.schoolname.value || this.studentname.value) {
    //   if (this.schoolname.value !== "" && this.studentname.value == "") {
    //     link(apiUrl.userlist, "GET", {}, { school: this.schoolname.value }).then(
    //       (ok: any) => {
    //         console.log(ok);
    //         this.userData.listdata = ok.data;
    //       }
    //     );
    //   } else if (this.schoolname.value == "" && this.studentname.value !== "") {
    //     link(apiUrl.userlist, "GET", {}, { name: this.studentname.value }).then(
    //       (ok: any) => {
    //         console.log(ok);
    //         this.userData.listdata = ok.data;
    //       }
    //     );
    //   } else {
    //     link(
    //       apiUrl.userlist,
    //       "GET",
    //       {},
    //       { school: this.schoolname.value, name: this.studentname.value }
    //     ).then((ok: any) => {
    //       console.log(ok);
    //       this.userData.listdata = ok.data;
    //     });
    //   }
    // }
    console.log(studentname);
    link(apiUrl.userlist, "GET", {}, { name: studentname }).then((ok: any) => {
      console.log(ok);
      this.userData.listdata = ok.data;
    });
  };
  //重置
  resetlist = () => {
    link(apiUrl.userlist).then((ok: any) => {
      this.userData.listdata = ok.data;
      console.log(this.userData.listdata);
    });
  };
  //删除操作
  //无法定义interface ??
  store = useStore();
  handleDelete = (index: number, row) => {
    console.log(index, row);
    this.store.dispatch("DEL_DATA", row);
  };
  //分页
  currentPage = ref(1);
  PageSize = ref(10);

  handleSizeChange = (val: number) => {
    this.PageSize.value = val;
    console.log(`${val} items per page`);
  };

  handleCurrentChange = (val: number) => {
    this.currentPage.value = val;
    console.log(`current page: ${val}`);
  };
  //初始化userData
  mounted() {
    link(apiUrl.userlist).then((ok: any) => {
      this.userData.listdata = ok.data;
      console.log(this.userData.listdata);
    });
  }
}
</script>

<style lang="less" scoped>
.ContentList {
  display: flex;
  flex-direction: column;
  .SelectMes {
    height: 1.12rem;
    border-radius: 0.06rem 0.06rem 0 0;
    border-bottom: 0.01rem solid rgba(242, 243, 245, 1);
    display: flex;
    justify-content: space-between;
    .left {
      margin-top: 0.2rem;
      //  padding-top: 0.2rem;
      padding-left: 0;
      width: 12rem;
      height: 0.8rem;
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      border-right: 0.02rem solid #f1f1f1;
      span {
        font-size: 0.14rem;
        font-weight: 400;
        color: rgba(78, 89, 105, 1);
        font-family: "PingFang SC";
        line-height: 0.22rem;
      }
      .leftinput {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 3.94rem;
        // margin-bottom: .16rem;
        .el-input {
          width: 2.56rem;
          height: 0.32rem;
        }
      }
      .leftselect {
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 3.94rem;
        .el-select {
          width: 2.56rem;
          height: 0.32rem;
        }
      }
      .other {
        margin-top: 0.16rem;
      }
    }
    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      margin-right: 0.5rem;
      margin-top: 0.2rem;
      height: 0.8rem;
      .bluebtn {
        width: 0.84rem;
        height: 0.32rem;
        border-radius: 2px;
        background: rgba(22, 93, 255, 1);
        color: rgba(255, 255, 255, 1);
        font-size: 14px;
        font-weight: 400;
        font-family: "PingFang SC";
        line-height: 0.22rem;
        margin: 0;
        img {
          margin-right: 0.12rem;
          width: 0.16rem;
          height: 0.16rem;
          border: 0.01rem dashed #adafb3;
        }
      }
      .whitebtn {
        width: 0.84rem;
        height: 0.32rem;
        border-radius: 2px;
        margin: 0;
        background: rgba(242, 243, 245, 1);
        color: rgba(29, 33, 41, 1);
        font-size: 14px;
        font-weight: 400;
        font-family: "PingFang SC";
        line-height: 0.22rem;
        img {
          margin-right: 0.12rem;
          width: 0.16rem;
          height: 0.16rem;
          border: 0.01rem dashed #adafb3;
        }
      }
    }
  }

  .UserList {
    padding: 0.2rem;
    .otherbutton {
      display: flex;
      justify-content: space-between;
      margin-bottom: 0.2rem;
      .el-button {
        width: 0.84rem;
        height: 0.32rem;
        border-radius: 2px;
      }
      .newbutton {
        background: rgba(22, 93, 255, 1);
        color: rgba(255, 255, 255, 1);
        font-size: 14px;
        font-weight: 400;
        font-family: "PingFang SC";
        line-height: 0.22rem;
      }
      .downbutton {
        background: rgba(242, 243, 245, 1);
        color: rgba(29, 33, 41, 1);
        font-size: 14px;
        font-weight: 400;
        font-family: "PingFang SC";
        line-height: 0.22rem;
      }
      img {
        margin-right: 0.12rem;
        width: 0.16rem;
        height: 0.16rem;
        border: 0.01rem dashed #adafb3;
      }
    }
    .detailList {
      .pagination {
        margin-top: 0.2rem;
        display: flex;
        flex-direction: row-reverse;
      }
    }
  }
}
</style>